import logging

import allure
import jsonpath

from utils.send_requests import send_jdbc_request


def json_extractor(case,res,all):
    if case["jsonExData"]:
        with allure.step("4.JSON提取"):
            for key, value in eval(case["jsonExData"]).items():
                value = jsonpath.jsonpath(res.json(), value)[0]
            # print("这是Key"+key)

                all[key] = value
            logging.info(f"4.json提取，根据{case['jsonExData']}提取数据，此时全局变量all为： {all}")

def jdbc_extractor(case,all):
    if case["sqlExData"]:
        with allure.step("4.提JDBC取"):
            for key, value in eval(case["sqlExData"]).items():
                value = send_jdbc_request(value)

                all[key] = value
        logging.info(f"4.jdbc提取，根据{case['sqlExData']}提取数据，此时全局变量all为： {all}")
